home *** CD-ROM | disk | FTP | other *** search
/ The Complete Utilities To…ka 501 Killer Utilities! / 501 Killer Utilities! (Macworld July 1995).cdr / Programming / metro-c-cpp-121 / C_C++_1.2.1 / INTO ‘Headers’ / INTO ‘Universal Headers’ / OSUtils.h < prev    next >
Encoding:
C/C++ Source or Header  |  1995-01-25  |  13.6 KB  |  562 lines  |  [TEXT/MPS ]

  1. /*
  2.      File:        OSUtils.h
  3.  
  4.      Copyright:    © 1984-1994 by Apple Computer, Inc.
  5.                  All rights reserved.
  6.  
  7.      Version:    Universal Interfaces 2.0a4 Wednesday, January 25, 1995. 
  8.  
  9.      Bugs?:        If you find a problem with this file, send the file and version
  10.                  information (from above) and the problem description to:
  11.  
  12.                      Internet:    apple.bugs@applelink.apple.com
  13.                      AppleLink:    APPLE.BUGS
  14.  
  15. */
  16.  
  17. #ifndef __OSUTILS__
  18. #define __OSUTILS__
  19.  
  20.  
  21. #ifndef __TYPES__
  22. #include <Types.h>
  23. #endif
  24. /*    #include <ConditionalMacros.h>                                */
  25.  
  26. #ifndef __MIXEDMODE__
  27. #include <MixedMode.h>
  28. #endif
  29.  
  30. #ifndef __MEMORY__
  31. #include <Memory.h>
  32. #endif
  33.  
  34. #ifdef __cplusplus
  35. extern "C" {
  36. #endif
  37.  
  38. #if GENERATINGPOWERPC
  39. #pragma options align=mac68k
  40. #endif
  41.  
  42. #ifdef __CFM68K__
  43. #pragma lib_export on
  44. #endif
  45.  
  46.  
  47. enum {
  48.     useFree                        = 0,
  49.     useATalk                    = 1,
  50.     useAsync                    = 2,
  51.     useExtClk                    = 3,                            /*Externally clocked*/
  52.     useMIDI                        = 4,
  53. /* Environs Equates */
  54.     curSysEnvVers                = 2,                            /*Updated to equal latest SysEnvirons version*/
  55. /* Machine Types */
  56.     envMac                        = -1,
  57.     envXL                        = -2,
  58.     envMachUnknown                = 0,
  59.     env512KE                    = 1,
  60.     envMacPlus                    = 2,
  61.     envSE                        = 3,
  62.     envMacII                    = 4,
  63.     envMacIIx                    = 5,
  64.     envMacIIcx                    = 6,
  65.     envSE30                        = 7,
  66.     envPortable                    = 8,
  67.     envMacIIci                    = 9,
  68.     envMacIIfx                    = 11,
  69. /* CPU types */
  70.     envCPUUnknown                = 0
  71. };
  72.  
  73. enum {
  74.     env68000                    = 1,
  75.     env68010                    = 2,
  76.     env68020                    = 3,
  77.     env68030                    = 4,
  78.     env68040                    = 5,
  79. /* Keyboard types */
  80.     envUnknownKbd                = 0,
  81.     envMacKbd                    = 1,
  82.     envMacAndPad                = 2,
  83.     envMacPlusKbd                = 3,
  84.     envAExtendKbd                = 4,
  85.     envStandADBKbd                = 5,
  86.     envPrtblADBKbd                = 6,
  87.     envPrtblISOKbd                = 7,
  88.     envStdISOADBKbd                = 8,
  89.     envExtISOADBKbd                = 9,
  90.     false32b                    = 0,                            /*24 bit addressing error*/
  91.     true32b                        = 1,                            /*32 bit addressing error*/
  92. /* result types for RelString Call */
  93.     sortsBefore                    = -1,                            /*first string < second string*/
  94.     sortsEqual                    = 0,                            /*first string = second string*/
  95.     sortsAfter                    = 1                                /*first string > second string*/
  96. };
  97.  
  98. enum {
  99. /* Toggle results */
  100.     toggleUndefined                = 0,
  101.     toggleOK                    = 1,
  102.     toggleBadField                = 2,
  103.     toggleBadDelta                = 3,
  104.     toggleBadChar                = 4,
  105.     toggleUnknown                = 5,
  106.     toggleBadNum                = 6,
  107.     toggleOutOfRange            = 7,                            /*synonym for toggleErr3*/
  108.     toggleErr3                    = 7,
  109.     toggleErr4                    = 8,
  110.     toggleErr5                    = 9,
  111. /* Date equates */
  112.     smallDateBit                = 31,                            /*Restrict valid date/time to range of Time global*/
  113.     togChar12HourBit            = 30,                            /*If toggling hour by char, accept hours 1..12 only*/
  114.     togCharZCycleBit            = 29,                            /*Modifier for togChar12HourBit: accept hours 0..11 only*/
  115.     togDelta12HourBit            = 28,                            /*If toggling hour up/down, restrict to 12-hour range (am/pm)*/
  116.     genCdevRangeBit                = 27,                            /*Restrict date/time to range used by genl CDEV*/
  117.     validDateFields                = -1,
  118.     maxDateField                = 10,
  119.     eraMask                        = 0x0001,
  120.     yearMask                    = 0x0002,
  121.     monthMask                    = 0x0004,
  122.     dayMask                        = 0x0008,
  123.     hourMask                    = 0x0010,
  124.     minuteMask                    = 0x0020,
  125.     secondMask                    = 0x0040,
  126.     dayOfWeekMask                = 0x0080,
  127.     dayOfYearMask                = 0x0100,
  128.     weekOfYearMask                = 0x0200,
  129.     pmMask                        = 0x0400,
  130.     dateStdMask                    = 0x007F                        /*default for ValidDate flags and ToggleDate TogglePB.togFlags*/
  131. };
  132.  
  133. enum {
  134.     eraField,
  135.     yearField,
  136.     monthField,
  137.     dayField,
  138.     hourField,
  139.     minuteField,
  140.     secondField,
  141.     dayOfWeekField,
  142.     dayOfYearField,
  143.     weekOfYearField,
  144.     pmField,
  145.     res1Field,
  146.     res2Field,
  147.     res3Field
  148. };
  149.  
  150. typedef SignedByte LongDateField;
  151.  
  152.  
  153. enum {
  154.     dummyType,
  155.     vType,
  156.     ioQType,
  157.     drvQType,
  158.     evType,
  159.     fsQType,
  160.     sIQType,
  161.     dtQType,
  162.     nmType
  163. };
  164.  
  165. typedef SignedByte QTypes;
  166.  
  167.  
  168. enum {
  169.     OSTrap,
  170.     ToolTrap
  171. };
  172.  
  173. typedef SignedByte TrapType;
  174.  
  175. struct SysParmType {
  176.     UInt8                            valid;
  177.     UInt8                            aTalkA;
  178.     UInt8                            aTalkB;
  179.     UInt8                            config;
  180.     short                            portA;
  181.     short                            portB;
  182.     long                            alarm;
  183.     short                            font;
  184.     short                            kbdPrint;
  185.     short                            volClik;
  186.     short                            misc;
  187. };
  188. typedef struct SysParmType SysParmType, *SysPPtr;
  189.  
  190. typedef struct QElem QElem;
  191.  
  192. typedef QElem *QElemPtr;
  193.  
  194. struct QElem {
  195.     QElemPtr                        qLink;
  196.     short                            qType;
  197.     short                            qData[1];
  198. };
  199. typedef struct QHdr QHdr;
  200.  
  201. typedef QHdr *QHdrPtr;
  202.  
  203. struct QHdr {
  204.     short                            qFlags;
  205.     QElemPtr                        qHead;
  206.     QElemPtr                        qTail;
  207. };
  208. /*
  209.         DeferredTaskProcPtr uses register based parameters on the 68k and cannot
  210.         be written in or called from a high-level language without the help of
  211.         mixed mode or assembly glue.
  212.  
  213.         In:
  214.          => dtParam         A1.L
  215. */
  216.  
  217. #if GENERATINGCFM
  218. typedef UniversalProcPtr DeferredTaskUPP;
  219. #else
  220. typedef Register68kProcPtr DeferredTaskUPP;
  221. #endif
  222.  
  223. struct DeferredTask {
  224.     QElemPtr                        qLink;
  225.     short                            qType;
  226.     short                            dtFlags;
  227.     DeferredTaskUPP                    dtAddr;
  228.     long                            dtParam;
  229.     long                            dtReserved;
  230. };
  231. typedef struct DeferredTask DeferredTask, *DeferredTaskPtr;
  232.  
  233. struct SysEnvRec {
  234.     short                            environsVersion;
  235.     short                            machineType;
  236.     short                            systemVersion;
  237.     short                            processor;
  238.     Boolean                            hasFPU;
  239.     Boolean                            hasColorQD;
  240.     short                            keyBoardType;
  241.     short                            atDrvrVersNum;
  242.     short                            sysVRefNum;
  243. };
  244. typedef struct SysEnvRec SysEnvRec;
  245.  
  246. struct MachineLocation {
  247.     Fract                            latitude;
  248.     Fract                            longitude;
  249.     union {
  250.         SInt8                            dlsDelta;                /*signed byte; daylight savings delta*/
  251.         long                            gmtDelta;                /*must mask - see documentation*/
  252.     } u;
  253. };
  254.  
  255. typedef struct MachineLocation MachineLocation;
  256.  
  257. struct DateTimeRec {
  258.     short                            year;
  259.     short                            month;
  260.     short                            day;
  261.     short                            hour;
  262.     short                            minute;
  263.     short                            second;
  264.     short                            dayOfWeek;
  265. };
  266. typedef struct DateTimeRec DateTimeRec;
  267.  
  268. typedef wide LongDateTime;
  269.  
  270. union LongDateCvt {
  271.     wide                            c;
  272.         struct {
  273.             UInt32                            lHigh;
  274.             UInt32                            lLow;
  275.         }                            hl;
  276. };
  277. typedef union LongDateCvt LongDateCvt;
  278.  
  279. union LongDateRec {
  280.         struct {
  281.             short                            era;
  282.             short                            year;
  283.             short                            month;
  284.             short                            day;
  285.             short                            hour;
  286.             short                            minute;
  287.             short                            second;
  288.             short                            dayOfWeek;
  289.             short                            dayOfYear;
  290.             short                            weekOfYear;
  291.             short                            pm;
  292.             short                            res1;
  293.             short                            res2;
  294.             short                            res3;
  295.         }                            ld;
  296.     short                            list[14];                    /*Index by LongDateField!*/
  297.         struct {
  298.             short                            eraAlt;
  299.             DateTimeRec                        oldDate;
  300.         }                            od;
  301. };
  302. typedef union LongDateRec LongDateRec;
  303.  
  304. typedef SInt8 DateDelta;
  305.  
  306. struct TogglePB {
  307.     long                            togFlags;                    /*caller normally sets low word to dateStdMask=$7F*/
  308.     ResType                            amChars;                    /*from 'itl0', but uppercased*/
  309.     ResType                            pmChars;                    /*from 'itl0', but uppercased*/
  310.     long                            reserved[4];
  311. };
  312. typedef struct TogglePB TogglePB;
  313.  
  314. typedef short ToggleResults;
  315.  
  316. enum {
  317.     uppDeferredTaskProcInfo = kRegisterBased
  318.          | REGISTER_ROUTINE_PARAMETER(1, kRegisterA1, SIZE_CODE(sizeof(long)))
  319. };
  320.  
  321. #if GENERATINGCFM
  322. #define NewDeferredTaskProc(userRoutine)        \
  323.         (DeferredTaskUPP) NewRoutineDescriptor((ProcPtr)(userRoutine), uppDeferredTaskProcInfo, GetCurrentArchitecture())
  324. #else
  325. #define NewDeferredTaskProc(userRoutine)        \
  326.         ((DeferredTaskUPP) (userRoutine))
  327. #endif
  328.  
  329. #if GENERATINGCFM
  330. #define CallDeferredTaskProc(userRoutine, dtParam)        \
  331.         CallUniversalProc((UniversalProcPtr)(userRoutine), uppDeferredTaskProcInfo, (dtParam))
  332. #else
  333. /* (*DeferredTaskProcPtr) cannot be called from a high-level language without the Mixed Mode Manager */
  334. #endif
  335.  
  336. extern pascal void LongDateToSeconds(const LongDateRec *lDate, LongDateTime *lSecs)
  337.  FOURWORDINLINE(0x2F3C, 0x8008, 0xFFF2, 0xA8B5);
  338. extern pascal void LongSecondsToDate(LongDateTime *lSecs, LongDateRec *lDate)
  339.  FOURWORDINLINE(0x2F3C, 0x8008, 0xFFF0, 0xA8B5);
  340. extern pascal ToggleResults ToggleDate(LongDateTime *lSecs, LongDateField field, DateDelta delta, short ch, const TogglePB *params)
  341.  FOURWORDINLINE(0x2F3C, 0x820E, 0xFFEE, 0xA8B5);
  342. extern pascal short ValidDate(const LongDateRec *vDate, long flags, LongDateTime *newSecs)
  343.  FOURWORDINLINE(0x2F3C, 0x820C, 0xFFE4, 0xA8B5);
  344. extern pascal Boolean IsMetric(void)
  345.  THREEWORDINLINE(0x3F3C, 0x0004, 0xA9ED);
  346. extern pascal SysPPtr GetSysPPtr(void)
  347.  THREEWORDINLINE(0x2EBC, 0x0000, 0x01F8);
  348.  
  349. #if !GENERATINGCFM
  350. #pragma parameter __D0 ReadDateTime(__A0)
  351. #endif
  352. extern pascal OSErr ReadDateTime(unsigned long *time)
  353.  ONEWORDINLINE(0xA039);
  354.  
  355. #if !GENERATINGCFM
  356. #pragma parameter GetDateTime(__A0)
  357. #endif
  358. extern pascal void GetDateTime(unsigned long *secs)
  359.  TWOWORDINLINE(0x20B8, 0x020C);
  360.  
  361. #if !GENERATINGCFM
  362. #pragma parameter __D0 SetDateTime(__D0)
  363. #endif
  364. extern pascal OSErr SetDateTime(unsigned long time)
  365.  ONEWORDINLINE(0xA03A);
  366.  
  367. #if !GENERATINGCFM
  368. #pragma parameter SetTime(__A0)
  369. #endif
  370. extern pascal void SetTime(const DateTimeRec *d)
  371.  TWOWORDINLINE(0xA9C7, 0xA03A);
  372.  
  373. #if !GENERATINGCFM
  374. #pragma parameter GetTime(__A0)
  375. #endif
  376. extern pascal void GetTime(DateTimeRec *d)
  377.  THREEWORDINLINE(0x2038, 0x020C, 0xA9C6);
  378. extern pascal void DateToSeconds(const DateTimeRec *d, unsigned long *secs);
  379.  
  380. #if !GENERATINGCFM
  381. #pragma parameter SecondsToDate(__D0, __A0)
  382. #endif
  383. extern pascal void SecondsToDate(unsigned long secs, DateTimeRec *d)
  384.  ONEWORDINLINE(0xA9C6);
  385. extern pascal void SysBeep(short duration)
  386.  ONEWORDINLINE(0xA9C8);
  387.  
  388. #if !GENERATINGCFM
  389. #pragma parameter __D0 DTInstall(__A0)
  390. #endif
  391. extern pascal OSErr DTInstall(DeferredTaskPtr dtTaskPtr)
  392.  ONEWORDINLINE(0xA082);
  393.  
  394. #if GENERATINGPOWERPC
  395. #define GetMMUMode() ((char)true32b)
  396. #define SwapMMUMode(x) (*(SInt8*)(x) = true32b)
  397. #else
  398. extern pascal SInt8 GetMMUMode( void )
  399.     TWOWORDINLINE( 0x1EB8, 0x0CB2 ); /* MOVE.b $0CB2,(SP) */
  400. #if !GENERATINGCFM
  401. #pragma parameter SwapMMUMode(__A0)
  402. #endif
  403. extern pascal void SwapMMUMode(SInt8 *mode)
  404.  THREEWORDINLINE(0x1010, 0xA05D, 0x1080);
  405. #endif
  406.  
  407. #if SystemSixOrLater
  408.  
  409. #if !GENERATINGCFM
  410. #pragma parameter __D0 SysEnvirons(__D0, __A0)
  411. #endif
  412. extern pascal OSErr SysEnvirons(short versionRequested, SysEnvRec *theWorld)
  413.  ONEWORDINLINE(0xA090);
  414. #else
  415. extern pascal OSErr SysEnvirons(short versionRequested, SysEnvRec *theWorld);
  416. #endif
  417.  
  418. #if !GENERATINGCFM
  419. #pragma parameter Delay(__A0, __A1)
  420. #endif
  421. extern pascal void Delay(long numTicks, long *finalTicks)
  422.  TWOWORDINLINE(0xA03B, 0x2280);
  423. /*
  424.     GetTrapAddress and SetTrapAddress are obsolete and should not
  425.     be used. Always use NGetTrapAddress and NSetTrapAddress instead.
  426.     The old routines will not be supported for PowerPC apps.
  427. */
  428. #if OLDROUTINENAMES && !GENERATINGCFM
  429.  
  430. #if !GENERATINGCFM
  431. #pragma parameter __A0 GetTrapAddress(__D0)
  432. #endif
  433. extern pascal UniversalProcPtr GetTrapAddress(short trapNum)
  434.  ONEWORDINLINE(0xA146);
  435.  
  436. #if !GENERATINGCFM
  437. #pragma parameter SetTrapAddress(__A0, __D0)
  438. #endif
  439. extern pascal void SetTrapAddress(UniversalProcPtr trapAddr, short trapNum)
  440.  ONEWORDINLINE(0xA047);
  441. #endif
  442. extern pascal UniversalProcPtr NGetTrapAddress(short trapNum, TrapType tTyp);
  443. extern pascal void NSetTrapAddress(UniversalProcPtr trapAddr, short trapNum, TrapType tTyp);
  444.  
  445. #if !GENERATINGCFM
  446. #pragma parameter __A0 GetOSTrapAddress(__D0)
  447. #endif
  448. extern pascal UniversalProcPtr GetOSTrapAddress(short trapNum)
  449.  ONEWORDINLINE(0xA346);
  450.  
  451. #if !GENERATINGCFM
  452. #pragma parameter SetOSTrapAddress(__A0, __D0)
  453. #endif
  454. extern pascal void SetOSTrapAddress(UniversalProcPtr trapAddr, short trapNum)
  455.  ONEWORDINLINE(0xA247);
  456.  
  457. #if !GENERATINGCFM
  458. #pragma parameter __A0 GetToolTrapAddress(__D0)
  459. #endif
  460. extern pascal UniversalProcPtr GetToolTrapAddress(short trapNum)
  461.  ONEWORDINLINE(0xA746);
  462.  
  463. #if !GENERATINGCFM
  464. #pragma parameter SetToolTrapAddress(__A0, __D0)
  465. #endif
  466. extern pascal void SetToolTrapAddress(UniversalProcPtr trapAddr, short trapNum)
  467.  ONEWORDINLINE(0xA647);
  468.  
  469. #if !GENERATINGCFM
  470. #pragma parameter __A0 GetToolboxTrapAddress(__D0)
  471. #endif
  472. extern pascal UniversalProcPtr GetToolboxTrapAddress(short trapNum)
  473.  ONEWORDINLINE(0xA746);
  474.  
  475. #if !GENERATINGCFM
  476. #pragma parameter SetToolboxTrapAddress(__A0, __D0)
  477. #endif
  478. extern pascal void SetToolboxTrapAddress(UniversalProcPtr trapAddr, short trapNum)
  479.  ONEWORDINLINE(0xA647);
  480. extern pascal OSErr WriteParam(void);
  481.  
  482. #if !GENERATINGCFM
  483. #pragma parameter Enqueue(__A0, __A1)
  484. #endif
  485. extern pascal void Enqueue(QElemPtr qElement, QHdrPtr qHeader)
  486.  ONEWORDINLINE(0xA96F);
  487.  
  488. #if !GENERATINGCFM
  489. #pragma parameter __D0 Dequeue(__A0, __A1)
  490. #endif
  491. extern pascal OSErr Dequeue(QElemPtr qElement, QHdrPtr qHeader)
  492.  ONEWORDINLINE(0xA96E);
  493. extern long SetCurrentA5(void)
  494.  THREEWORDINLINE(0x200D, 0x2A78, 0x0904);
  495.  
  496. #if !GENERATINGCFM
  497. #pragma parameter __D0 SetA5(__D0)
  498. #endif
  499. extern long SetA5(long newA5)
  500.  ONEWORDINLINE(0xC18D);
  501. #if !SystemSevenOrLater
  502. extern pascal void Environs(short *rom, short *machine);
  503. #endif
  504.  
  505. #if !GENERATINGCFM
  506. #pragma parameter __D0 InitUtil
  507. #endif
  508. extern pascal OSErr InitUtil(void)
  509.  ONEWORDINLINE(0xA03F);
  510. #if GENERATING68K
  511. extern pascal Boolean SwapInstructionCache(Boolean cacheEnable);
  512. extern pascal void FlushInstructionCache(void)
  513.  TWOWORDINLINE(0x7001, 0xA098);
  514. extern pascal Boolean SwapDataCache(Boolean cacheEnable);
  515. extern pascal void FlushDataCache(void)
  516.  TWOWORDINLINE(0x7003, 0xA098);
  517. extern pascal void FlushCodeCache(void)
  518.  ONEWORDINLINE(0xA0BD);
  519.  
  520. #if !GENERATINGCFM
  521. #pragma parameter FlushCodeCacheRange(__A0, __A1)
  522. #endif
  523. extern pascal void FlushCodeCacheRange(void *address, unsigned long count)
  524.  TWOWORDINLINE(0x7009, 0xA098);
  525. #endif
  526.  
  527. #if !GENERATINGCFM
  528. #pragma parameter ReadLocation(__A0)
  529. #endif
  530. extern pascal void ReadLocation(MachineLocation *loc)
  531.  FOURWORDINLINE(0x203C, 0x000C, 0x00E4, 0xA051);
  532.  
  533. #if !GENERATINGCFM
  534. #pragma parameter WriteLocation(__A0)
  535. #endif
  536. extern pascal void WriteLocation(const MachineLocation *loc)
  537.  FOURWORDINLINE(0x203C, 0x000C, 0x00E4, 0xA052);
  538. #if GENERATINGPOWERPC
  539. extern pascal UniversalProcPtr *GetTrapVector(short trapNumber);
  540. #endif
  541. #if OLDROUTINENAMES
  542. #define LongDate2Secs(lDate, lSecs) LongDateToSeconds(lDate, lSecs)
  543. #define LongSecs2Date(lSecs, lDate) LongSecondsToDate(lSecs, lDate)
  544. #define IUMetric() IsMetric()
  545. #define Date2Secs(d, secs) DateToSeconds(d, secs)
  546. #define Secs2Date(secs, d) SecondsToDate(secs, d)
  547. #endif
  548.  
  549. #ifdef __CFM68K__
  550. #pragma lib_export off
  551. #endif
  552.  
  553. #if GENERATINGPOWERPC
  554. #pragma options align=reset
  555. #endif
  556.  
  557. #ifdef __cplusplus
  558. }
  559. #endif
  560.  
  561. #endif /* __OSUTILS__ */
  562.